package com.test.application.loadFile.loadTXT.demo2;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * 描述: TODO
 * 作者: yanruizhi
 * 时间: 2024/9/19 17:23
 */
@Service
@Slf4j
public class LoadTXT2 {
    public void loadTXT() {
        //获取要读取的文件地址
        URL resource = LoadTXT2.class.getClassLoader().getResource("file/test.txt");
        String filePath =resource.getPath();

        try {
            String string = new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8);
            log.info(string);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
